package com.ymtms.arrivalofgoods.service.impl;

import com.ymtms.arrivalofgoods.dao.CheckGoodsReceiveMapper;
import com.ymtms.arrivalofgoods.dao.GoodsbillMasterMapper;
import com.ymtms.arrivalofgoods.dao.GoodsbillReceoptMainMapper;
import com.ymtms.arrivalofgoods.dao.ViewEmpStateScMapper;
import com.ymtms.arrivalofgoods.exception.CheckException;
import com.ymtms.arrivalofgoods.pojo.CheckGoodsReceive;
import com.ymtms.arrivalofgoods.pojo.GoodsbillReceoptMain;
import com.ymtms.arrivalofgoods.pojo.ViewEmpStateSc;
import com.ymtms.arrivalofgoods.service.CheckGoodsReceiveService;
import com.ymtms.arrivalofgoods.service.GoodsbillMasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CheckGoodsReceiveServiceImpl implements CheckGoodsReceiveService {

    @Autowired
    private CheckGoodsReceiveMapper checkGoodsReceiveMapper;
    @Autowired
    private GoodsbillReceoptMainMapper goodsbillReceoptMainMapper;
    @Autowired
    private GoodsbillMasterMapper goodsbillMasterMapper;
    @Autowired
    private ViewEmpStateScMapper viewEmpStateScMapper;

    @Override
    public void modifyStatusByKeys(Integer[] keys) {

        try {

            checkGoodsReceiveMapper.updateCheckReceiveByArray(keys);
            for (Integer key : keys) {
                Integer employeePkid = goodsbillMasterMapper.selectByPrimaryKey(goodsbillReceoptMainMapper.selectByPrimaryKey(key).getGoodsBillpkid()).getEmployeePkid();
                ViewEmpStateSc viewEmpStateSc = viewEmpStateScMapper.selectStatusByEid(employeePkid);
                switch (viewEmpStateSc.getState()) {
                    case "省内1":
                        viewEmpStateScMapper.updateStatusToCompany(viewEmpStateSc.getEiid());
                        break;
                    case "省内2":
                        viewEmpStateScMapper.updateStatusToProvince(viewEmpStateSc.getEiid());
                        break;

                    case "省外":
                        viewEmpStateScMapper.updateStatusToCompany(viewEmpStateSc.getEiid());
                        break;
                }
            }
        } catch (CheckException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void updateByReceiptId(Integer gid) {


        checkGoodsReceiveMapper.updateByReceiptId(gid);
    }
}
